package com.fifth.commodity.service.impl;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.Unit;
import com.fifth.commodity.mapper.UnitMapper;
import com.fifth.commodity.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UnitServiceImpl implements UnitService {
    @Autowired
    private UnitMapper unitMapper;

    @Override
    public CommonResult UnitSelectAll(Unit unit) {

        List<Unit> units = unitMapper.UnitSelectAll(unit);

        return new CommonResult(2000,"查询成功",units);
    }

    @Override
    public CommonResult UnitInsert(Unit unit) {
        int units = unitMapper.insert(unit);
        return new CommonResult(2000,"添加成功",units);
    }

    @Override
    public CommonResult UnitUpdate(Unit unit) {
        int i = unitMapper.updateById(unit);
        return new CommonResult(2000,"修改成功",i);
    }

    @Override
    public CommonResult UnitDelete(String id) {
        int delete = unitMapper.deleteById(id);
        return new CommonResult(2000,"删除成功",delete);
    }

    /**
     * 查询所有单位
     * @return
     */
    @Override
    public CommonResult selectAllUnit() {
        List<Unit> units = unitMapper.selectList(null);
        return new CommonResult(2000,"查询成功",units);
    }
}
